<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item
        ><a href="/">教学情况统计管理列表</a></el-breadcrumb-item
      >
    </el-breadcrumb>
    <el-card>
      <!-- 搜索、添加、自定义列 -->
      <el-row :gutter="20">
        <el-col :span="12">
          <el-input placeholder="请输入课程号名称" v-model="query.classCode">
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getList"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="3">
          <el-button type="primary" @click="showAddDialog">添加申请</el-button>
        </el-col>
        <el-col :span="3">
          <el-button type="success" @click="showSetColumn">自定义列</el-button>
        </el-col>
      </el-row>
      <!-- 内容列表 -->
      <el-table :data="list" border stripe>
        <el-table-column label="ID" type="index"></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '地点').show"
          label="地点"
          prop="address"
          width="150"
        ></el-table-column>
         <!-- 审批操作 -->
        <el-table-column label="审批操作" width="80">
          <template slot-scope="scope">
            <!-- 审批 -->
            <el-tooltip effect="dark" content="重审" placement="top">
              <el-button type="warning" size="mini" @click="reset(scope.row)"
                >重审</el-button
              >
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '课程号').show"
          label="课程号"
          prop="classCode"
          width="100"
        >
          <template slot-scope="scope">
            {{
              scope.row.independent == 0
                ? "是"
                : scope.row.independent == 1
                ? "否"
                : "暂无"
            }}
          </template></el-table-column
        >
        <el-table-column
          v-if="showColumns.find((i) => i.label == '课序号').show"
          label="课序号"
          prop="classIndex"
          width="120"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '每次上课课时').show"
          label="每次上课课时"
          prop="classTime"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '教学情况统计信息编号').show"
          label="教学情况统计信息编号"
          prop="id"
          width="150"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '学生人数').show"
          label="学生人数"
          prop="number"
          width="80"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '承担教学任务名称').show"
          label="承担教学任务名称"
          prop="task"
          width="120"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '教师名').show"
          label="教师名"
          prop="teacher"
          width="70"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '实验室使用时间').show"
          label="实验室使用时间"
          prop="timeInfo"
          width="110"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '实际上课周数').show"
          label="实际上课周数"
          prop="weekNum"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '上课周次').show"
          label="上课周次"
          prop="weekRemark"
          width="100"
        >
        </el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '创建时间').show"
          label="创建时间"
          prop="createTime"
          width="100"
          ><template slot-scope="scope">
            {{ scope.row.createTime.substring(0, 10) }}
          </template></el-table-column
        >
        <el-table-column
          v-if="showColumns.find((i) => i.label == '最后修改时间').show"
          label="最后修改时间"
          prop="modifyTime"
          width="100"
          ><template slot-scope="scope">
            {{ scope.row.createTime.substring(0, 10) }}
          </template></el-table-column
        >
        <el-table-column
          v-if="showColumns.find((i) => i.label == '备注').show"
          label="备注"
          prop="remarks"
          width="120"
        ></el-table-column>

        <!-- 操作 -->
        <el-table-column label="操作" width="130">
          <template slot-scope="scope">
            <!-- 查看 -->
            <el-tooltip effect="dark" content="查看" placement="top">
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="showDetailDialog(scope.row)"
              ></el-button>
            </el-tooltip>
            <!-- 修改 -->
            <!-- <el-tooltip effect="dark" content="修改" placement="top">
              <el-button
                type="warning"
                icon="el-icon-edit"
                size="mini"
                @click="showEditDialog(scope.row)"
              ></el-button>
            </el-tooltip> -->
             <!-- 删除 -->
            <el-tooltip
              v-if="scope.row.account != 'admin'"
              effect="dark"
              content="删除"
              placement="top"
            >
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                @click="del(scope.row.id)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pageNum"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 自定义列 -->
    <CustomColumn ref="columns" :showColumns="showColumns"></CustomColumn>

    <!-- 详情 -->
    <el-dialog
      title="教学情况统计详情"
      :visible.sync="showDetailVisible"
      width="70%"
      @close="hideDetailDialog"
      center
    >
      <el-form :model="detail" label-width="80px">
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="实验室使用时间:" label-width="150px">
              <el-select style="width: 100%" v-model="detail.timeInfo" disabled>
                <el-option label="周一" :value="0"></el-option>
                <el-option label="周二" :value="1"></el-option>
                <el-option label="周三" :value="2"></el-option>
                <el-option label="周四" :value="3"></el-option>
                <el-option label="周五" :value="4"></el-option>
                <el-option label="其它" :value="null"></el-option
              ></el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="承担教学任务名称:" label-width="150px">
              <el-input v-model="detail.task" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10"
            ><el-form-item label="地点:" label-width="150px">
              <el-input
                v-model="detail.address"
                disabled
              ></el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="课程号:" label-width="150px">
              <el-input v-model="detail.classCode" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="课序号:" label-width="150px">
              <el-input v-model="detail.classIndex" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="教师名:" label-width="150px">
              <el-input v-model="detail.teacher" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="学生人数:" label-width="150px">
              <el-input v-model="detail.number" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="每次上课课时:" label-width="150px">
              <el-input v-model="detail.classTime" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="实际上课周数:" label-width="150px">
              <el-input v-model="detail.weekNum" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="上课周次:" label-width="150px">
              <el-input v-model="detail.weekRemark" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注:">
          <el-input
            type="textarea"
            v-model="detail.remarks"
            disabled
          ></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="hideDetailDialog">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 新增 -->
    <el-dialog
      title="新增教学情况统计"
      :visible.sync="showAddVisible"
      width="70%"
      @close="hideAddDialog"
      center
    >
      <el-form :model="addForm" ref="addFormRef" label-width="80px">
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="实验室使用时间:" label-width="150px">
              <el-select style="width: 100%" v-model="addForm.timeInfo">
                <el-option label="周一" :value="0"></el-option>
                <el-option label="周二" :value="1"></el-option>
                <el-option label="周三" :value="2"></el-option>
                <el-option label="周四" :value="3"></el-option>
                <el-option label="周五" :value="4"></el-option>
                <el-option label="其它" :value="null"></el-option
              ></el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="承担教学任务名称:" label-width="150px">
              <el-input v-model="addForm.task"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10"
            ><el-form-item label="地点:" label-width="150px">
              <el-input v-model="addForm.address"></el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="课程号:" label-width="150px">
              <el-input v-model="addForm.classCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="课序号:" label-width="150px">
              <el-input v-model="addForm.classIndex"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="教师名:" label-width="150px">
              <el-input v-model="addForm.teacher"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="学生人数:" label-width="150px">
              <el-input v-model="addForm.number"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="每次上课课时:" label-width="150px">
              <el-input v-model="addForm.classTime"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="实际上课周数:" label-width="150px">
              <el-input v-model="addForm.weekNum"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="上课周次:" label-width="150px">
              <el-input v-model="addForm.weekRemark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注:">
          <el-input type="textarea" v-model="addForm.remarks"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hideAddDialog">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 修改 -->
    <el-dialog
      title="修改教学情况统计"
      :visible.sync="showEditVisible"
      width="70%"
      @close="hideEditDialog"
      center
    >
      <el-form :model="editForm" ref="editFormRef" label-width="80px">
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="实验室使用时间:" label-width="150px">
              <el-select style="width: 100%" v-model="editForm.timeInfo">
                <el-option label="周一" :value="0"></el-option>
                <el-option label="周二" :value="1"></el-option>
                <el-option label="周三" :value="2"></el-option>
                <el-option label="周四" :value="3"></el-option>
                <el-option label="周五" :value="4"></el-option>
                <el-option label="其它" :value="null"></el-option
              ></el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="承担教学任务名称:" label-width="150px">
              <el-input v-model="editForm.task"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10"
            ><el-form-item label="地点:" label-width="150px">
              <el-input v-model="editForm.address"></el-input> </el-form-item
          ></el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="课程号:" label-width="150px">
              <el-input v-model="editForm.classCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="课序号:" label-width="150px">
              <el-input v-model="editForm.classIndex"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="教师名:" label-width="150px">
              <el-input v-model="editForm.teacher"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="学生人数:" label-width="150px">
              <el-input v-model="editForm.number"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="每次上课课时:" label-width="150px">
              <el-input v-model="editForm.classTime"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="实际上课周数:" label-width="150px">
              <el-input v-model="editForm.weekNum"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="10">
            <el-form-item label="上课周次:" label-width="150px">
              <el-input v-model="editForm.weekRemark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注:">
          <el-input type="textarea" v-model="editForm.remarks"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hideEditDialog">取 消</el-button>
        <el-button type="primary" @click="edit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import md5 from "js-md5";
import CustomColumn from "../components/CustomColumn.vue";
export default {
  components: { CustomColumn },
  data() {
    return {
      //领用人信息
      info: {},
      //分类编号选择项
      options: [],
      // 查询条件
      query: {
        approvalStatus: 1,
        name: "",
        categoryNumber: "",
        pageNum: 1,
        pageSize: 10,
      },
      // 内容列表
      list: [],
      // 内容总条数
      total: 0,
      query1: {
        name: "",
        categoryNumber: "",
        pageNum: 1,
        pageSize: "",
      },
      // 初始化显示字段
      showColumns: [
        { label: "地点", show: true },
        { label: "审批状态", show: true },
        { label: "课程号", show: true },
        { label: "课序号", show: true },
        { label: "每次上课课时", show: true },
        { label: "教学情况统计信息编号", show: true },
        { label: "学生人数", show: true },
        { label: "承担教学任务名称", show: true },
        { label: "教师名", show: true },
        { label: "实验室使用时间", show: true },
        { label: "实际上课周数", show: true },
        { label: "上课周次", show: true },
        { label: "创建时间", show: true },
        { label: "最后修改时间", show: true },
        { label: "备注", show: true },
      ],
      // 是否显示详情
      showDetailVisible: false,
      // 数据详情
      detail: {},
      // 是否显示新增
      showAddVisible: false,
      // 新增数据
      addForm: {},
      // 是否显示修改
      showEditVisible: false,

      // 是否审批
      approvalForm: false,
      // 修改数据
      editForm: {},
    };
  },
  created() {
    this.getList();
    // this.getList1();
    // this.getList2();
  },
  methods: {
    // 显示自定义列
    showSetColumn() {
      this.$refs.columns.dialogVisible = true;
    },
    // 获取内容列表
    getList() {
      this.$http
        .post("/v1/api/teachStatistics/page", this.query)
        .then((res) => {
          if (res.data.code == 0) {
            this.list = res.data.data.list;
            this.total = res.data.data.total;
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    //获取资源分类编号
    getList1() {
      this.$http.post("/v1/api/categories/page", this.query1).then((res) => {
        if (res.data.code == 0) {
          // this.list = res.data.data.list;
          // this.total = res.data.data.total;
          // console.log(res.data.data.list);
          var gotList = res.data.data.list;
          gotList.forEach((v) => {
            this.options.push({
              value: v.name,
              id: v.id,
            });
          });
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //获取领用人列表
    getList2() {
      var userInfo = JSON.parse(localStorage.getItem("userInfo"));
      console.log(userInfo.account);
      this.info = userInfo;
    },
    //监听分类编号改变
    handleAdd() {
      this.query.categoryNumber = this.name;
      console.log(this.name);
    },
    handleChange() {
      this.query.categoryNumber = this.name;
      this.getList();
      console.log(this.name);
    },
    // 监听 pageSize 改变的事件
    handleSizeChange(pageSize) {
      this.query.pageSize = pageSize;
      this.getList();
    },
    // 监听 page 改变的事件
    handleCurrentChange(page) {
      this.query.pageNum = page;
      this.getList();
    },
    // 显示详情
    showDetailDialog(row) {
      this.detail = row;
      this.showDetailVisible = true;
    },
    // 隐藏详情
    hideDetailDialog() {
      this.detail = {};
      this.showDetailVisible = false;
    },
    // 显示新增
    showAddDialog() {
      this.addForm = {
        address: "理四-",
        classCode: "",
        classIndex: "",
        classTime: "",
        number: "",
        remarks: "",
        task: "",
        teacher: "",
        timeInfo: "",
        weekNum: "",
        weekRemark: "",
      };
      this.showAddVisible = true;
    },
    // 隐藏新增
    hideAddDialog() {
      this.showAddVisible = false;
    },
    // 新增
    add() {
      this.$refs.addFormRef.validate((valid) => {
        if (valid) {
          // this.addForm.password = md5(this.addForm.password);
          this.$http
            .post("/v1/api/teachStatistics", this.addForm)
            .then((res) => {
              if (res.data.code == 0) {
                this.getList();
                this.$message.success("新增成功");
                this.showAddVisible = false;
              } else {
                this.$message.error(res.data.msg);
              }
            });
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
    // 删除
    del(id) {
      this.$confirm("此操作将永久删除该教学情况统计, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http.delete("/v1/api/teachStatistics/" + id).then((res) => {
            if (res.data.code == 0) {
              this.getList();
              this.$message.success("删除成功");
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消");
        });
    },
    // 显示修改
    showEditDialog(row) {
      this.editForm = row;
      this.showEditVisible = true;
    },
    // 隐藏修改
    hideEditDialog() {
      this.showEditVisible = false;
    },
    reset(row) {
      this.approvalForm = row;
      this.approvalForm.approvalStatus = 0;
      console.log(this.approvalForm);
      this.showpass = true;
      this.$http.put("/v1/api/teachStatistics", this.approvalForm).then((res) => {
        if (res.data.code == 0) {
          this.getList();
          this.$message.success("已递交重审");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    pass(row) {
      this.approvalForm = row;
      this.approvalForm.approvalStatus = 1;
      console.log(this.approvalForm);
      this.showpass = true;
      this.$http
        .put("/v1/api/teachStatistics", this.approvalForm)
        .then((res) => {
          if (res.data.code == 0) {
            this.getList();
            this.$message.success("修改成功");
          } else {
            this.$message.error(res.data.msg);
          }
        });
    },
    reject(row) {
      this.approvalForm = row;
      this.approvalForm.approvalStatus = 2;
      console.log(this.approvalForm);
      this.showpass = true;
      this.$http
        .put("/v1/api/teachStatistics", this.approvalForm)
        .then((res) => {
          if (res.data.code == 0) {
            this.getList();
            this.$message.success("修改成功");
          } else {
            this.$message.error(res.data.msg);
          }
        });
    },
    // 修改
    edit() {
      this.$refs.editFormRef.validate((valid) => {
        if (valid) {
          this.$http
            .put("/v1/api/teachStatistics", this.editForm)
            .then((res) => {
              if (res.data.code == 0) {
                this.getList();
                this.$message.success("修改成功");
                this.showEditVisible = false;
                this.showpass = false;
              } else {
                this.$message.error(res.data.msg);
              }
            });
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.el-breadcrumb {
  margin-bottom: 15px;
  font-size: 12px;
}
</style>
